﻿using System;
using System.Collections.Generic;
using System.Linq;
using log4net;

namespace Truncation.Detector.WPF
{
    public class Report
    {
        private readonly List<Result> _results = new List<Result>();
        private static readonly ILog Log = LogManager.GetLogger("Detail.Reporter");
        public int AddResult(string file, string label, string lang, int line)
        {
            Result result = _results.FirstOrDefault(r => file == r.FileName && label == r.Label && line == r.Line);
            if (result != null && !result.Contain(lang))
            {
                result.Append(lang);
                return 1;
            }
            if (result == null)
            {
                result = new Result {FileName = file, Label = label, Line = line};
                result.Append(lang);
                _results.Add(result);
                return 0;
            }
            return -1;
        }

        public void Output()
        {
            foreach (var result in _results)
            {
                Log.Info(result.ToString());
            }
        }
    }
}